<?php
/**
 * UserGroupFunctionModel
 *
 * PHP Version 5.4
 *
 * @author liuxuTJ  <liuxuphp@icesmart.cn>
 */
namespace Model;
use Think\Model;
/**
 * Class UserGroupFunctionModel
 */
class UserGroupFunctionModel extends BaseModel
{
    /**
     * construct
     */
    public function __construct()
    {
        $this->tableName  = 'user_group_functions';
        $this->primaryKey = 'id';
        parent::__construct();
    }

    public function structure($category)
    {

        //获取顶级分类
        foreach ($category as $v) {
            if ($v['categoryId'] == 0) {
                $cateogryTree[] = $v;
            } else {
                $childCategory [] = $v;
            }
        }
        //获取顶级分类的子分类
        foreach ($cateogryTree as $k => $v) {
            foreach ($childCategory as $k_2 => $v_2) {
                if ($v['id'] == $v_2['categoryId']) {
                    $cateogryTree[$k]['child'][$k_2] = $v_2;
                }
            }
        }

        return $cateogryTree;
    }
}